package leyou.controller;

import leyou.service.UploadService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/*
/upload/image
 */
@RestController
@RequestMapping("upload")
public class UploadController {

    @Autowired
    UploadService uploadService;
    //上传文件是post请求
    //http://localhost:8082/upload/image 进不来啊
    @PostMapping("image")
    public ResponseEntity<String> uploadImage(@RequestParam("file")MultipartFile file){
        String url = this.uploadService.upload(file);
        if (StringUtils.isBlank(url)){
            return ResponseEntity.badRequest().build();
        }
        return ResponseEntity.status(HttpStatus.CREATED).body(url);
    }


    @PostMapping("image1")
    @ResponseBody
    private String image1(){
        System.out.println(123);
        return "hello";
    }


    @GetMapping("hi")
    @ResponseBody
    private String fun(){

        return "hello";
    }

}

